import os
import re
os.system("wget http://models.gazebosim.org/ -O models.txt")


def replace(data):
    return data.replace('href="','').replace('/"','')

models = ""
with open("models.txt") as f:
    models = f.read()

result = re.findall('href="[a-zA-z_0-9]+/"',models)
urls = [replace(url) for url in result]


for url in urls:
    os.system("mkdir -p models/{}/".format(url))
    os.system("wget http://models.gazebosim.org/{}/model.tar.gz -O models/{}_model.tar.gz".format(url,url))
    os.system("cd models/ && tar -xvf {}_model.tar.gz".format(url))


print(urls,len(urls))